package com.example.test9;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

public class ContactsAdapter extends BaseAdapter {

    private List<Contacts> contacts;
    private Context context;

    public ContactsAdapter(List<Contacts> contacts, Context context) {
        this.contacts = contacts;
        this.context = context;
    }
    @Override
    public int getCount() {
        return contacts.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        if(view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.contacts_item,viewGroup,false);

        }
        TextView contactsdetail = (TextView) view.findViewById(R.id.contacts_detail);
        contactsdetail.setText(
                contacts.get(i).toString()
                        + "contacts_name:" + contacts.get(i).getName()
                        + ",contacts_number:" + contacts.get(i).getNumber()
                        + ",contacts_gender:" + contacts.get(i).getGender()

        );
        return view;
    }
}
